/*
 * @Description: 
 * @Author: rendc
 * @Date: 2024-10-12 17:11:00
 * @LastEditors: rendc
 * @LastEditTime: 2024-10-12 17:32:29
 */
/**
 * BaoZiShop
 */
public class BaoZiShop {
  // 数量
  private int meatBaoCount;
  private int veggBaoCount;

  // 做包子
  public synchronized void makeBaoZi(String type) {
    if (type == "vegg") {
      veggBaoCount++;
      // System.out.println("做了一个菜包");
    } else if (type == "meat") {
      meatBaoCount++;
      // System.out.println("做了一个肉包");
    }
    notifyAll();
  }

  public synchronized String sellBaoZi() {
    // 卖包子
    while (meatBaoCount == 0 && veggBaoCount == 0) {
      try {
        wait();
        System.out.println("等待制作");
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
    if (meatBaoCount > 0) {
      meatBaoCount--;
      return "meat";
    } else {
      veggBaoCount--;
      return "vegg";
    }
  }
}